package com.job.util;


import com.job.common.Constant;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;


public class OssUtil implements Constant {

    public static COSClient getOssClient(){
        String endpoint = END_POINT;

        //初始化用户身份
        String secretId = ACCESS_KEY_ID;
        String secretKey = ACCESS_KEY_SECRET;

        // 2 设置 bucket 的地域
        // clientConfig 中包含了设置 region, https(默认 http),超时, 代理等 set 方法
        Region region = new Region(endpoint);
        ClientConfig clientConfig = new ClientConfig(region);
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);

        // 这里建议设置使用 https 协议
        // 从 5.6.54 版本开始，默认使用了 https
        clientConfig.setHttpProtocol(HttpProtocol.http);
        // 3 生成 cos 客户端。
        COSClient cosClient = new COSClient(cred, clientConfig);
        return cosClient;
    }
}
